package com.library.dao;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Repository
public class AdminDao {

    @Resource
    private SqlSessionTemplate sqlSession;

    private final String namespace="com.library.dao.AdminDao.";

    public int getMatchCount(String username, String passwd) {
        Map<String,Object> map=new HashMap<>();
        map.put("username",username);
        map.put("password",passwd);
        return sqlSession.selectOne(namespace+"getMatchCount",map);
    }

    public Long getAdminUsernameId(String username) {
        return sqlSession.selectOne(namespace+"getAdminUsernameId",username);
    }

    public String getPasswd(long id) {
        return sqlSession.selectOne(namespace+"getPasswd",id);
    }

    public int resetPasswd(Long id, String newpasswd) {
        Map<String,Object> map=new HashMap<>();
        map.put("admin_id",id);
        map.put("password",newpasswd);
        return sqlSession.update(namespace+"resetPasswd",map);
    }
}
